<?php

/**
 * uniBoard ACP Badwords Filter
 *
 * Light and fast forum solution for web 2.0-like communities.
 *
 * @package		uniBoard
 * @author		Rafał Pitoń
 * @license		http://www.gnu.org/licenses/gpl-3.0.html
 * @since		Version 0.1
 * 
 * ------------------------------------------------------------------------
 * 
 * $Date: 2010-09-15 17:35:38 +0000 (Wed, 15 Sep 2010) $
 * $Revision: 61 $
 * $Author: rafio.xudb@gmail.com $
 */

// ------------------------------------------------------------------------

class action_badwords{
	
	/**
	 * Main class pointer
	 *
	 * @var object
	 */
	
	private $appCore		= NULL;
	
	// ------------------------------------------------------------------------

	/**
	 * Initialise Action
	 *
	 * @param object $appCore
	 */
	
	function __construct( $appCore){
		
		// Store appCore pointer
		$this -> appCore = $appCore;
		
		// Add language string
		$appCore -> output -> js_vars['l_delete_item_sure'] =  $appCore -> lang['delete_item_sure'];
		
		// Cache output
		ob_start();
		
		// Open table block
		echo $appCore -> output -> openTableBlock();
		
		// Draw header
		echo $appCore -> output -> tableHeader( array(
			array(
				'left_float width_quarter',
				$appCore -> lang['acp_badwords_list_find']
			),
			array(
				'left_float width_quarter',
				$appCore -> lang['acp_badwords_list_replace']
			),
			array(
				'right_float width_medium',
				$appCore -> lang['actions']
			)
		));
				
		// Select Badwords
		$appCore -> db -> query( 'SELECT *
		FROM ' . DB_PREFIX . 'badwords
		ORDER BY word_find');
		
		// Parse result
		while ( $badword_result = $appCore -> db -> fetch_array())
		{
			// Draw row
			echo $appCore -> output -> tableRow('
				<div class="cell left_float width_quarter">
					<b>' . htmlspecialchars( $badword_result[1]) . '</b>
				</div>
				<div class="cell left_border left_float width_quarter">
					<b>' . htmlspecialchars( $badword_result[2]) . '</b>
				</div>
				<div class="cell left_border right_float width_medium center">
					<a href="' . $appCore -> adminLink( 'act=edit_badword&do=edit&badword=' . $badword_result[0]) . '">' . $appCore -> output -> drawImage( 'action_edit', $appCore -> lang['edit']) . '</a>
					<a href="' . $appCore -> adminLink( 'act=edit_badword&do=delete&badword=' . $badword_result[0]) . '" class="delete_confirm">' . $appCore -> output -> drawImage( 'action_delete', $appCore -> lang['delete']) . '</a>
				</div>');
		}
		
		// Free result
		$appCore -> db -> freeResult();
		
		// Close table block
		echo $appCore -> output -> closeTableBlock();
		
		// New Group Button
		echo $appCore -> output -> openForm( $appCore -> adminLink( 'act=new_badword'));
		echo $appCore -> output -> openFormBlock( $appCore -> lang['acp_new_bardword_form']);
		echo $appCore -> output -> submitButton( $appCore -> lang['acp_new_bardword_form_submit']);
		echo $appCore -> output -> closeFormBlock();
		echo $appCore -> output -> closeForm();
		
		// Draw output
		$appCore -> output -> draw( $appCore -> lang['acp_badwords'], array( $appCore -> adminLink( 'act=badwords') => $appCore -> lang['acp_badwords']), ob_get_clean());
				
	}

}